<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" th:href="@{/res/css/amazeui.min.css}"/>
    <link rel="stylesheet" th:href="@{/res/css/admin.css}"/>
    <script th:src="@{/js/jquery-1.11.3.min.js}"></script>
    <script th:src="@{/myplugs/js/plugs.js}"></script>
</head>

<body>
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">店铺管理</strong><small></small></div>
    </div>

    <hr>

    <div class="am-g">
        <div class="am-u-sm-12">
            <form class="am-form">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                    <tr>
                        <th class="table-id">ID</th>
                        <th class="table-title">店铺名</th>
                        <th class="table-type">类别</th>
                    </tr>
                    </thead>

                    <tbody id="mytbody">

                    </tbody>

                </table>
                <hr>
                <div>
                    <a href="" target="right" id="add">
                        <input type="button" id="gotoupdate" class="am-btn am-btn-primary am-round" value="增加店铺" />
                    </a>
                </div>
            </form>
        </div>
    </div>
</div>
</body>

<script>
    //id从url得到
    var result=new Object();
    result=getParameter();
    var uid=result["uid"];
    console.log(uid);

    $(function () {
        $("#add").attr("href", "/addStore?uid=" + uid);

        $.ajax({
            type:'POST',
            url:'/store/getStoreList',
            data:{uid:uid},
            dataType:'json',
            success:function (mydata) {
                console.log(mydata);
                showData(mydata);
            },
            error:function () {
                alert("error");
            }
        });
    })


    function showData(data) {
        var str= "";
        for(var i = 0; i <data.length; i++){
            str = "<tr><td>" + data[i].id + "</td><td>" + data[i].name + "</td><td>" + data[i].type + "</td></tr>"
            $("#mytbody").append(str);
        }
    }

    //解析url传值
    function getParameter() {
        var url=location.search;//获取url?后面的内容
        var result=new Object();
        if(url.indexOf("?")!= -1){
            var str=url.substr(1);
            strs=str.split("&");
            for(var i=0;i<strs.length;i++){
                result[strs[i].split("=")[0]]=decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return result;
    }
</script>
</html>